# your_project_name/asgi.py
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')  # ⚠️必须在所有 Django 相关之前

import django
django.setup()

from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from django.core.asgi import get_asgi_application
import message.routing  # ✅只能在 django.setup() 后引入

application = ProtocolTypeRouter({
    "http": get_asgi_application(),
    "websocket": AuthMiddlewareStack(
        URLRouter(
            message.routing.websocket_urlpatterns
        )
    ),
})
